package com.wiser.ohosservice.slice;

import com.wiser.ohosservice.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        Button buttonStartService = (Button) findComponentById(ResourceTable.Id_buttonStartService);
        Button buttonStopService = (Button) findComponentById(ResourceTable.Id_buttonStopService);

        buttonStartService.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intentService = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName("com.wiser.ohosservice.ServiceAbility")
                        .build();
                intentService.setOperation(operation);
                startAbility(intentService);
            }
        });

        buttonStopService.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intentService = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName("com.wiser.ohosservice.ServiceAbility")
                        .build();
                intentService.setOperation(operation);
                stopAbility(intentService);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
